﻿using MusicStore.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MusicStore.Controllers
{
    
    public class HomeController : Controller
    {
        MusicStoreDB db = new MusicStoreDB();
        public ActionResult Index()
        {
            var albums = db.Albums
                .OrderByDescending(x => x.AlbumId)
                .Take(5)
                .ToList();
            return View(albums);
        }
        public ActionResult Search(string s)//搜索查找
        {
            var albums = db.Albums
                .Include("Artist")
                .Include("Genre")
                .Where(x => x.Title.Contains(s) || x.Genre.Name.Contains(s) || x.Artist.Name.Contains(s));
            ViewBag.returnUrl = Request.UrlReferrer;
            return View(albums);
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";
            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";
            return View();
        }
    }
}